<?php

class EstadoModel extends Database {	
	
	const TABLE = "uf";
        
	const NOME = "nome_uf";
	const SIGLA = "sigla_uf";
        const ID =  "id_uf";

	public function select($fields = "*", $condition = null, $limit = null) {
            if(is_array($fields)) $fields = implode(",", $fields);
            
            $this_condition = " 1 = 1 ORDER BY ".self::ID;
            if(is_null($condition)) $condition = $this_condition;
            else $condition .= " AND $this_condition";
            
            $res = parent::select(self::TABLE, $fields, $condition, $limit);		
            $ana = $this->getAnnalisses();		
            while(($row = $ana->fetchObject($res)) !== false) {
                $estado = new Estado( isset($row->{self::ID})? $row->{self::ID} : 0, 
                                      isset($row->{self::NOME})? ($row->{self::NOME}): "",
                                      isset($row->{self::SIGLA})? $row->{self::SIGLA}: "");
                $estados[] = $estado;		
            }
            return $estados;
	} 	
}
?>
